package com.custom.jdbc.interfaces;

import com.custom.jdbc.configuration.DbDataSource;
import com.custom.jdbc.executebody.SqlExecutorBody;
import com.custom.jdbc.session.CustomSqlSessionHelper;
import com.custom.jdbc.session.DbTxLevel;

import java.sql.Connection;
import java.sql.SQLException;

/**
 * 自定义sql会话接口
 * @author  Xiao-Bai
 * @since  2022/10/23 22:37
 */
public interface CustomSqlSession {

    /**
     * 获取当前连接对象
     */
    Connection getConnection() throws SQLException;

    /**
     * 检查连接状态
     */
    void checkConnState(DbDataSource dbDataSource) throws SQLException;

    /**
     * 开启会话
     * @see  Connection#TRANSACTION_READ_UNCOMMITTED
     * @see Connection#TRANSACTION_READ_COMMITTED
     * @see Connection#TRANSACTION_REPEATABLE_READ
     * @see Connection#TRANSACTION_SERIALIZABLE
     */
    void openSession(DbTxLevel level) throws SQLException;

    /**
     * 关闭会话
     */
    void closeSession() throws SQLException;

    /**
     * 提交事务
     */
    void commit() throws SQLException;

    /**
     * 回滚事务
     */
    void rollback() throws SQLException;

    /**
     * 关闭资源
     */
    void closeResources() throws SQLException;

    /**
     * 是否为自动提交
     */
    boolean isAutoCommit() throws SQLException;

    /**
     * 执行体
     */
    SqlExecutorBody getExecuteBody();

    /**
     * 获取SqlSession助手
     */
    CustomSqlSessionHelper getHelper();

}
